package reduce;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class ReduceStreamDemo {

    public static void main(String[] args) {
        List<Integer> demo = new ArrayList<>();
        demo.add(2);
        demo.add(4);
        demo.add(1);
        demo.add(5);

        Optional<Integer> reduce = demo.stream().reduce((x, y) -> x + y);
        System.out.println(reduce.get());
        //求最大值
        Optional<Integer> reduce1 = demo.stream().reduce((x, y) -> x > y ? x : y);
        System.out.println(reduce1.get());

    }
}
